package com.zhny.sprinkler.irrigation.machine.rtu.plugin;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.zhny.aiot.plugin.ICenterFacilities;
import com.zhny.aiot.plugin.IDevice;
import com.zhny.aiot.plugin.core.utils.ConfigUtils;
import com.zhny.aiot.plugin.modbus.ModemServer;
import com.zhny.aiot.plugin.modbus.device.ModemConfig;
import com.zhny.aiot.plugin.modbus.device.ModemDeviceFactory;
import com.zhny.aiot.plugin.modbus.handler.model.ModemRequestMessage;
import com.zhny.aiot.plugin.model.CommandEntry;
import com.zhny.aiot.plugin.model.DeviceEntity;
import com.zhny.aiot.plugin.model.FactoryType;
import com.zhny.aiot.plugin.model.StoreEntity;
import com.zhny.sprinkler.irrigation.machine.rtu.plugin.model.SprinklerRTUStoreEntry;
import org.pf4j.Extension;
import org.pf4j.Plugin;
import org.pf4j.PluginWrapper;

import java.util.ArrayList;
import java.util.List;

public class SprinklerRTUPlugin extends Plugin {
    public SprinklerRTUPlugin(PluginWrapper wrapper) {
        super(wrapper);
    }

    @Extension
    public static class RollFilmFactory extends ModemDeviceFactory<SprinklerRTUStoreEntry> {

        public ModemRequestMessage getRequestMessage(ModemConfig modemConfig) {
            return null;
        }

        @Override
        public List<CommandEntry> supportCommandClasses(){
            List<CommandEntry> commands = new ArrayList<> ();
            commands.add(CommandEntry.valueOf("sprinklerOpen", "喷灌机打开", "无参数",null));
            commands.add(CommandEntry.valueOf("sprinklerClose", "喷灌机关闭", "无参数",null));
            commands.add(CommandEntry.valueOf("sprinklerStop", "喷灌机停止", "无参数",null));
            commands.add(CommandEntry.valueOf("sprinklerQuery", "喷灌机查询", "无参数",null));
            commands.add(CommandEntry.valueOf("sprinklerModelClockwise", "喷灌机顺时针模式", "无参数",null));
            commands.add(CommandEntry.valueOf("sprinklerModelAnticlockwise", "喷灌机逆时针模式", "无参数",null));
            commands.add(CommandEntry.valueOf("sprinklerModelQuery", "喷灌机模式查询", "无参数",null));
            commands.add(CommandEntry.valueOf("pressureQuery", "压力查询", "无参数",null));
            return commands;
        }

        public IDevice createDevice(ICenterFacilities iCenterFacilities, DeviceEntity entity) {
            return new SprinklerRTUDevice (ModemServer.getInstance ().getEngine () ,this,iCenterFacilities,entity);
        }

        public Class<? extends StoreEntity> storeClass() {
            return SprinklerRTUStoreEntry.class;
        }

        public String getId() {
            return "zhny-sprinkler-rtu-plugin";
        }

        public String getName() {
            return "智慧喷灌机RTU插件";
        }

        public FactoryType getType() {
            return FactoryType.OpenCloseController;
        }
    }
}
